package com.luolc.emojirain.utils;

import java.util.Random;

/**
 * Utils for {@link Random}.
 *
 * @author LuoLiangchen
 * @since 2016/12/14
 */

public class Randoms {
    private static Random random = new Random();
    private static int ranges = 0;

    /**
     * Sets the seed of this random number
     *
     * @param seed random number
     */
    public static void setSeed(long seed) {
        random.setSeed(seed);
    }

    /**
     * 获取随机数
     *
     * @return float value between 0.0 and 1.0
     */
    public static float floatStandard() {
        return random.nextFloat();
    }

    /**
     * 获取下降偏移量
     *
     * @param mean 左偏移
     * @param delta 右偏移
     * @return 相对偏移值
     */
    public static float floatAround(float mean, float delta) {
        return floatInRange(mean - delta, mean + delta);
    }

    /**
     * 获取范围内的随机数
     *
     * @param left 左区间
     * @param right 右区间
     * @return 随机数
     */
    public static float floatInRange(float left, float right) {
        return left + (right - left) * random.nextFloat();
    }

    /**
     * 获取高斯值
     *
     * @return 高斯值
     */
    public static double positiveGaussian() {
        return Math.abs(random.nextGaussian());
    }

    /**
     * 获取X轴起始位置
     *
     * @return 坐标
     */
    public static float getStartX() {
        return random.nextInt(ranges);
    }

    /**
     * 获取X轴终止位置
     *
     * @return 坐标
     */
    public static float getStopX() {
        return ranges * (random.nextFloat() * 2 - 1);
    }

    /**
     * 设置初始宽度
     *
     * @param ranges 标准宽度
     */
    public static void setRanges(int ranges) {
        Randoms.ranges = ranges;
    }
}
